﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Markup;

namespace UIT.Web.Markup
{
    public enum Source
    {
        QueryString,
        Cookie,
        Session,
        Application,
        Post,
    }

    public class HttpContext : MarkupExtension
    {
        public HttpContext()
        {

        }

        public HttpContext(string key)
        {
            Key = key;
        }

        public Source Source { get; set; }

        public string Key { get; set; }

        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            switch (Source)
            {
                case Source.QueryString:
                    return System.Web.HttpContext.Current.Request.QueryString[Key];
                case Source.Cookie:
                    return System.Web.HttpContext.Current.Request.Cookies[Key].Value;
                case Source.Session:
                    return System.Web.HttpContext.Current.Session[Key];
                case Source.Application:
                    return System.Web.HttpContext.Current.Application[Key];
                case Source.Post:
                    return System.Web.HttpContext.Current.Request.Form[Key];
                default:
                    throw new NotSupportedException();
            }
        }
    }
}
